#include "matrix_float2.h"


matrix_float2::matrix_float2(void)
{
	create_matrix( 0, 0 );
	this->mptr = nullptr;
}

matrix_float2::matrix_float2( int r, int c )
{
	create_matrix( r, c );
}

matrix_float2::~matrix_float2(void)
{
	delete_matrix();
}


void matrix_float2::create_matrix( int r, int c )
{
	this->r_size = r;
	this->c_size = c;
	this->mptr = std::unique_ptr<float>(new float[r]);
	for( int i = 0; i < r; i++ )
	{
		mptr.get()[i] = *std::unique_ptr<float>(new float[c]);
	}

}

void matrix_float2::delete_matrix()
{
	this->r_size = 0;
	this->c_size = 0;
}

void matrix_float2::set( float value, int r, int c )
{
	if( (r >= 0) && (r < this->r_size) )
	{
		if( (c >= 0) && (c < this->c_size) )
		{
			//this->mptr[r][c] = value;
			this->mptr.get()[r] = value;
		}
	}
}

void matrix_float2::read_from_keyboard()
{
	float temp;

	if( this->r_size == 0 || this->c_size == 0 )
		return;

	for( int i = 0; i < this->r_size; i++ )
	{
		for( int j = 0; j < this->c_size; j++ )
		{
			std::cout << "\nWrite a float to put at position [" << i << "][" << j << "]" << " : ";
			std::cin >> temp;
			set( temp, i, j );
		}
	}
}

void matrix_float2::print()
{
	for( int i = 0; i < this->r_size; i++ )
	{
		for( int j = 0; j < this->c_size; j++ )
		{
			std::cout <<"[" << mptr[i][j] << "]";
		}
		std::cout << std::endl;
	}
}
